package com.beimi.room.cmd;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.beimi.net.AbstractRoomCmd;
import com.beimi.net.proto.BeiMiClient;
import com.beimi.room.RoomPlayer;
import com.corundumstudio.socketio.SocketIOClient;
import com.next.core.util.GenericAnnotation;

@GenericAnnotation(type = "createroom")
public class CmdCreateRoom extends AbstractRoomCmd {

	@Override
	public void execute(SocketIOClient client, String data) {
		
		BeiMiClient beiMiClient = JSON.parseObject(data , BeiMiClient.class);
		String token = beiMiClient.getToken();
		
		RoomPlayer player = matchPlayerMgr.getPlayer(client.getSessionId().toString());
		System.err.println("onconnect " + client.getSessionId() + this);
		if (player == null) {
			player = new RoomPlayer();
			player.setToken(token);
			player.setClient(client);
			matchPlayerMgr.addMatchPlayer(client.getSessionId().toString(), player);
		}
		
		List<RoomPlayer> list = new ArrayList<>();
		list.add(player);
		gameService.createMajiongWithAI(list);
	}
}
